package co.fitstart.entity.user;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.site.Site;
import co.fitstart.entity.user.enums.VisitChannel;

@Entity
@Table(name = "visitor_record")
@PersistentFormat
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class VisitorRecord {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 姓名 */
    private String name;
    
    /** 手机号 */
    private String mobile;
    
    /** 首次需求 */
    private String demand;
    
    /** 学员来访渠道 */
    @Enumerated(EnumType.ORDINAL)
    private VisitChannel visitChannel;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private Site site;
    
    /** 首次接触时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Type(type = "date")
    private Date occurDate;
    
    /** 接待人 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Principal receiver;
    
    /** 操作人 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @PersistentFormat
    private Principal principal;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * 
     */
    public VisitorRecord() {
        
    }
    
    /**
     * 
     * @return
     */
    public VisitorRecord initilize() {
        this.occurDate = new Date();
        return this;
    }
    
    /**
     * 
     * @param site
     * @return
     */
    public VisitorRecord initilize(Site site) {
        this.site = site;
        this.occurDate = new Date();
        return this;
    }
    
    /**
     * 
     * @param site
     * @return
     */
    public VisitorRecord editSite(Site site) {
        this.site = site;
        return this;
    }
    
    /**
     * 
     * @param principal
     * @return
     */
    public VisitorRecord editPrincipal(Principal principal) {
        this.principal = principal;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public VisitorRecord disable() {
        this.disabled = true;
        return this;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getDemand() {
        return demand;
    }

    public void setDemand(String demand) {
        this.demand = demand;
    }

    public VisitChannel getVisitChannel() {
        return visitChannel;
    }

    public void setVisitChannel(VisitChannel visitChannel) {
        this.visitChannel = visitChannel;
    }

    public Site getSite() {
        return site;
    }

    public void setSite(Site site) {
        this.site = site;
    }

    public Date getOccurDate() {
        return occurDate;
    }

    public void setOccurDate(Date occurDate) {
        this.occurDate = occurDate;
    }

    public Principal getReceiver() {
        return receiver;
    }

    public void setReceiver(Principal receiver) {
        this.receiver = receiver;
    }

    public Principal getPrincipal() {
        return principal;
    }

    public void setPrincipal(Principal principal) {
        this.principal = principal;
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
